﻿Public Class EczaneFaturaDokumu
	Inherits ProcessReport

	Public Overrides Sub GenericEvent(ByVal e As ProcessEventArgs)
		Select Case e.EventType
			Case EventType.Initialize
				Text = "Eczane Fatura Dökümü"
				InitialHelp = "Yıl ve ay bilgilerini girin."
				AddCombo("@donem", "Dönem", "q@select distinct yil*100+ay as kod, ltrim(yil)+'/'+right('0'+ltrim(ay),2) as ad from ssdmerkez..recete where yil < 2020 order by 1 desc", "", "--first--", "Dönem bilgisini girmeniz gerekir")
				AddField("GenericCombo[name=tur;label=Rapor Türü]", "nl;width=15;source=1,Eczane toplamları|2,Eczane bazında döküm|3,Eczane pusula dökümü", "1")
			Case EventType.ValidateForm
				Rs = Saglik.Eczane.ReceteListesi(Remote, Mid(Input("donem"), 1, 4), Mid(Input("donem"), 5, 2))
				Rs.CreateSuperset("eczkod,sadi,eczadi,sum(ilactopfiat),sum(ssd10),sum(sig20),sum(ssdtopfiat),sum(kdv)")
				Rs.Superset.CreateSuperset("sum(sumilactopfiat),sum(sumssd10),sum(sumsig20),sum(sumssdtopfiat),sum(sumkdv)")
				e.Result = True
			Case EventType.ReportHeader
				Report.PrintHeader("ECZANELER İLAÇ ÖDEMELERİ")
			Case EventType.PageHeader
				Report.PrintPageHeader("Dönem: " & Trim(Mid(Input("Donem"), 1, 4)) & "/" & Trim(Mid(Input("Donem"), 5, 2)), "Döküm Tar. : " & Remote.SysDate)
				If Input("tur") = "3" Then Report.PrintPageHeader(Rs.Superset("eczkod") & " " & Rs.Superset("eczadi") & " (" & Rs.Superset("sadi") & ")")
				Select Case Input("tur")
					Case "1" : Report.SetColumns("Ecz.Kod;Eczane Adı;İlaç Toplam;İsk.;Sig.%20;Toplam;KDV", "1;4;2;2;2;2;2", "c;l;m;m;m;m;m", "--")
					Case "2" : Report.SetColumns("Fatura;Reçete;İst.;İlaç Toplam;İsk.;Sig.%20;Toplam;KDV", "2;2;1;2;2;2;2;2", "c;c;c;m;m;m;m;m", "--")
					Case "3" : Report.SetColumns("Fatura;Reçete;İst.;İlaç Toplam;İsk.;Sig.%20;Toplam;KDV", "2;2;1;2;2;2;2;2", "c;c;c;m;m;m;m;m", "--")
				End Select
			Case EventType.ReportDetail
				Do Until Rs.Superset.EOF
					Select Case Input("tur")
						Case "1"
							Report.Print(Rs.Superset("eczkod"), Rs.Superset("eczadi"), Rs.Superset("sumilactopfiat"), Rs.Superset("sumssd10"), Rs.Superset("sumsig20"), Rs.Superset("sumssdtopfiat"), Rs.Superset("sumkdv"))
						Case "2", "3"
							If Input("tur") = "2" Then Report.PrintTotal("<cs=8><l>" & Rs.Superset("eczkod") & " " & Rs.Superset("eczadi") & " (" & Rs.Superset("sadi") & ")")
							Rs.CreateSubset("eczkod='" & Rs.Superset("eczkod") & "'")
							Do Until Rs.Subset.EOF
								Report.Print(Rs.Subset("faturano"), Rs.Subset("receteno"), Rs.Subset("istsekli"), Rs.Subset("ilactopfiat"), Rs.Subset("ssd10"), Rs.Subset("sig20"), Rs.Subset("ssdtopfiat"), Rs.Subset("kdv"))
								Rs.Subset.MoveNext()
							Loop
							Report.PrintTotal("<cs=3><l>TOPLAM " & Rs.Subset.Count & " KAYIT", Rs.Superset("sumilactopfiat"), Rs.Superset("sumssd10"), Rs.Superset("sumsig20"), Rs.Superset("sumssdtopfiat"), Rs.Superset("sumkdv"))
							Report.SkipLine()
							If Input("tur") = "3" Then Report.EndPage()
					End Select
					Rs.Superset.MoveNext()
				Loop
				Select Case Input("tur")
					Case "1" : Report.PrintTotal("<cs=2><l>TOPLAM " & Rs.Superset.Count & " KAYIT", Rs.Superset.Superset("sumsumilactopfiat"), Rs.Superset.Superset("sumsumssd10"), Rs.Superset.Superset("sumsumsig20"), Rs.Superset.Superset("sumsumssdtopfiat"), Rs.Superset.Superset("sumsumkdv"))
				End Select
		End Select
	End Sub

End Class
